home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 280_01 / quick.c < prev    next >
Text File  |  1989-01-11  |  1KB  |  56 lines

  1. /* [quick.c of JUGPDS Vol.46] */
  2. /*
  3. *****************************************************************
  4. *                                *
  5. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  6. *            49-114 Kawauchi-Sanjuunin-machi        *
  7. *            Sendai, Miyagi 980                          *
  8. *            Phone: 0222-61-3219                *
  9. *                                *
  10. *       Modifird by Toshiya Oota   (JUG-CPM No.10)              *
  11. *                   Sakae ko-po 205                 *
  12. *            5-19-6 Hosoda                *
  13. *            Katusikaku Tokyo 124            *
  14. *                                *
  15. *        for MS-DOS Lattice C V3.1J & 80186/V20/V30    *
  16. *                                *
  17. *    Compiler Option: -ccu -k0(1) -ms -n -v -w        *
  18. *                                *
  19. *    Edited & tested by Y. Monma (JUG-CP/M Disk Editor)    *
  20. *            &  T. Ota   (JUG-CP/M Sub Disk Editor)    *
  21. *                                *
  22. *****************************************************************
  23. */
  24.  
  25. /* Library functions for Software Tools */
  26.  
  27. #include "stdio.h"
  28. #include "dos.h"
  29. #include "ctype.h"
  30. #include "tools.h"
  31.  
  32. void quick(v, l, r, comp, exch)
  33. char    *v[];
  34. int    l, r;
  35. int    (*comp)(), (*exch)();
  36. {
  37. char    *vx;
  38. int    i, j;
  39.  
  40.     i = l;  j = r;
  41.     vx = v[ (l+r)/2 ];
  42.     while(i <= j) {
  43.         while( (*comp)(v[i], vx) < 0 )
  44.             i++;
  45.         while( (*comp)(vx, v[j]) < 0 )
  46.             j--;
  47.         if(i <= j) {
  48.             (*exch)(&v[j], &v[i]);
  49.             i++;
  50.             j--;
  51.             }
  52.         }
  53.     if(l < j) quick(v,l,j,comp,exch);
  54.     if(i < r) quick(v,i,r,comp,exch);
  55. }
  56.